#!/bin/gawk -f
# script to modify the command file for the aqdrst script
# arguments (required): coordinp (=1/2/3/4/5), restrinp, oldmap, mr
# the mr argument is in fact not used anymore
# new additions: multi and terseness

{
    line[++count] = $0
}

END {
    for ( i=1; i<=count; i++ ) {

# restrinp definition in file overrides argument -- NO LONGER
#	if ( ( line[i] ~ /set *restrinp / ) ||
#	     ( line[i] ~ /set *restrtyp / )   ) {
#	    split( line[i], r )
#	    restrinp = r[3]
#	    continue
#	}

# coordinp and coordtyp (old name for coordinp) arguments override definitions in file
# oldmap argument overrides definition in file
# skip mr definition in file
	if (   ( line[i] ~ /set *coordinp / ) || 
	       ( line[i] ~ /set *coordtyp / ) || 
	       ( line[i] ~ /set *oldmap / )   || 
	       ( line[i] ~ /set *restrinp / ) || 
	       ( line[i] ~ /set *multiple / ) || 
	       ( line[i] ~ /set *terseness / ) || 
               ( line[i] ~ /set *mr / )         ) {
	    continue
	}

	print line[i]
    }

    if ( coordinp == 1 ) print "set coordinp pdb"
    if ( coordinp == 2 ) print "set coordinp pdbn"
    if ( coordinp == 3 ) print "set coordinp biosym"
    if ( coordinp == 4 ) print "set coordinp pdbx"
    if ( coordinp == 5 ) print "set coordinp pdbm"

    print "set oldmap " oldmap
    print "set restrinp " tolower( restrinp )

    if ( multi == 0 ) print "set multiple off"    
    if ( terseness != 0 ) print "set terseness "terseness 
}
